package com.agentframework.core.provider;

import com.agentframework.core.plan.ReviewConst;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.chat.prompt.PromptTemplate;
import org.springframework.ai.tool.ToolCallback;

import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.function.Consumer;

/**
 * @author wangjun
 **/
public class HumanLlm extends Llm {

    public HumanLlm() {
        this(null, null);
    }

    public HumanLlm(Provider provider, ChatMemory chatMemory) {
        super(provider, chatMemory, null);
    }

    @Override
    public Message call(Prompt prompt, Consumer<ChatClient.AdvisorSpec> advisorSpecConsumer, List<ToolCallback> toolCallbacks, Map<String, Object> toolContext) {
        Scanner scanner = new Scanner(System.in);
        String rsp = scanner.nextLine().trim();

        if (ReviewConst.EXIT_WORDS.contains(rsp.toLowerCase())) {
            scanner.close();
            System.exit(0);
        }
        scanner.close();
        return new PromptTemplate(rsp).createMessage();
    }

}
